package thread.demo.futureTask;

import java.util.concurrent.*;

public class FutureTaskTest002 {
  public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException {
    FutureTask<String> futureTask = new FutureTask<>(() -> {
      System.out.println("任务开始 ...");
      TimeUnit.SECONDS.sleep(2);
      System.out.println("任务结束 ...");
      return "OK";
    });
    
    new Thread(futureTask).start();
    
//    ExecutorService executorService = Executors.newFixedThreadPool(1);
//    executorService.execute(futureTask);
    
    // 如果时间到了，但是任务还没结束的话，直接报错。
    System.out.println(futureTask.get());
  }
}
